#!/bin/bash

directory=$1

if [ ! -d "$directory" ]; then
  echo "目录不存在或无法访问！"
  exit 1
fi

if [ -z "$2" ]; then
  echo "请提供区别行数的阈值作为第二个参数！"
  exit 1
fi

threshold=$2

files=$(find "$directory" -type f)

for file1 in $files; do
  for file2 in $files; do
    if [ "$file1" = "$file2" ]; then
      continue
    fi
    lines_file1=$(wc -l < "$file1")
    lines_file2=$(wc -l < "$file2")
    diff_lines=$(diff --unchanged-line-format="" --new-line-format="%L" --old-line-format="%L" "$file1" "$file2" | wc -l)
    if [ "$diff_lines" -lt "$threshold" ]; then
    file1name=$(basename "$file1")
    file2name=$(basename "$file2")
      echo "$file1name $file2name $diff_lines $lines_file1 $lines_file2"
    fi
  done
done
